package com.xwtec.juc.c_007;

import java.util.concurrent.TimeUnit;

/**
 * @Author: zt
 * @Date: 2021/3/19 16:33
 */
public class Account {

    private String name;
    private Double balance=0.0;

    public void setAccount(String name, Double balance) {
        this.name = name;

        try {
            TimeUnit.MILLISECONDS.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        this.balance = balance;
    }

    public double getBalance(String name){
        return this.balance;
    }

    public static void main(String[] args) {
        Account a = new Account();
        new Thread(()->{
            a.setAccount("zhangsan",100.0);
        }).start();

        try {
            TimeUnit.MILLISECONDS.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            double balance = a.getBalance("zhangsan");
            System.out.println(balance);
        }).start();
    }
}
